package com.itheima.tcp3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*
接收 客户端的数据
并给 客户端 发送数据

 */
public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(1314);
        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
       //字节 -> 字符
        InputStreamReader reader = new InputStreamReader(is);
        int  c;
        while((c=reader.read())!=-1){
            System.out.println((char)c);
        }
        // 获取输出流
        OutputStream os = accept.getOutputStream();
       // os.write("瞅你咋地".getBytes());
        //字符 ->字节
        OutputStreamWriter writer = new OutputStreamWriter(os);
        writer.write("瞅你咋地");
        writer.flush();// 字符流  和缓冲流
        //        //告诉客户端 我的数据结束了
        accept.shutdownOutput();
        ss.close();

    }
}
